package org.shj.spark.core.secondsort

import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.shj.spark.util.Util

object SecondSortDemo {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf
    conf.setAppName("SecondSortDemo").setMaster("local[*]")
    val sc = new SparkContext(conf)
    
    val lines = sc.textFile(Util.fullPath("secondsort.txt"))
    val pair = lines.map(line => {
      val arr = line.split("\\s+")
      val key = new SecondSortKey(arr(0).toInt, arr(2).toInt)
      (key, line)
    })
    pair.sortByKey(false).foreach(item => println(item._2))
    
    sc.stop()
  }
}